﻿<UserControl x:Class="Emcc.TeamSystem.TaskBoard.UIElements.EditItemControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:DataObjects="clr-namespace:Emcc.TeamSystem.TaskBoard.Core.DataObjects;assembly=Emcc.TeamSystem.TaskBoard.Core"
    xmlns:ValueConverters="clr-namespace:Emcc.TeamSystem.TaskBoard.UIElements.ValueConverters"
    MaxHeight="400" MaxWidth="600">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/EditControlTemplates.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <ValueConverters:ControlTemplateSelector x:Key="TemplatePicker" />
            <ValueConverters:BoolToVisibilityConverter x:Key="VisibilityConverter" />
        </ResourceDictionary>
    </UserControl.Resources>
    <Border BorderBrush="Black" BorderThickness="2" Background="White" Padding="10">
        <Grid>
            <DockPanel>
                <StackPanel Height="30" Orientation="Horizontal" DockPanel.Dock="Top" TextBlock.FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" TextBlock.FontSize="16">
                    <TextBlock Text="{Binding ControlItemCollection.ControlItems[0].TaskBoardItem[System.WorkItemType]}" />
                    <TextBlock xml:space="preserve"> - (</TextBlock>
                    <TextBlock Text="{Binding ControlItemCollection.ControlItems[0].TaskBoardItem[System.Id]}" />
                    <TextBlock>)</TextBlock>
                </StackPanel>
                <TextBlock Name="ValidationErrors" Foreground="Red" DockPanel.Dock="Top" TextWrapping="Wrap" />
                <ListView DockPanel.Dock="Top" ItemsSource="{Binding ControlItemCollection.ControlItems}">
                    <ListView.Resources>
                        <Style TargetType="ListViewItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        </Style>
                    </ListView.Resources>
                    <ListView.View>
                        <GridView x:Name="EditGridView">
                            <GridView.Columns>
                                <GridViewColumn Header="Field">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate DataType="{x:Type DataObjects:ControlItem}">
                                            <TextBlock FontWeight="Bold" Text="{Binding DisplayText}" ToolTip="{Binding HelpText}" />
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Header="Value" CellTemplateSelector="{StaticResource TemplatePicker}" />
                            </GridView.Columns>
                        </GridView>
                    </ListView.View>
                </ListView>
            </DockPanel>
            <Button 
                Name="DiscardButton"
                Visibility="{Binding Path=ControlItemCollection.ControlItems[0].TaskBoardItem.ValueProvider.IsNew, Converter={StaticResource VisibilityConverter}}" 
                Click="DiscardButton_Click" 
                Width="150" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Top"
                Content="Discard" 
                />
            <Button Name="CloseButton" Click="CloseButton_Click" Width="150" HorizontalAlignment="Right" VerticalAlignment="Top">Close</Button>
        </Grid>
    </Border>
</UserControl>
